package com.h2cloud.T.Generic;

/**
 * @Package: com.h2cloud.T
 * @ClassName: GenericClassDemo
 * @Author: h2cloud
 * @CreateTime: 2021/8/8 8:56 下午
 * @Description:
 */

import lombok.AllArgsConstructor;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

/**
 * @author qiyu
 * @date 2020-09-16 22:10
 */

/**
 * @author qiyu
 * @date 2020-09-16 22:10
 */
public class _2_extendsTest {

    public static void main(String[] args) {

        ArrayList<Chinese> chineseList = new ArrayList<>();
        chineseList.add(new Chinese("李健"));
        chineseList.add(new Chinese("周深"));

        ArrayList<Japanese> japaneseList = new ArrayList<>();
        japaneseList.add(new Japanese("三浦春马"));
        japaneseList.add(new Japanese("瑛太"));


        List<? extends Human> humanList = chineseList;

        Human lee = humanList.get(0);
        Human chou = humanList.get(1);
        System.out.println(lee + "&" + chou);


        humanList = japaneseList;
        Human haRuMa = humanList.get(0);
        Human eiTa = humanList.get(1);
        System.out.println(haRuMa + "&" + eiTa);


        // 不能存数据
        // humanList.add(new Japanese("三浦春马"));
        // humanList.add(new Human("三浦春马"));

    }

    @AllArgsConstructor
    @ToString
    static class Human {
        private String name;
    }

    public static class Chinese extends Human {
        public Chinese(String name) {
            super(name);
        }
    }

    public static class Japanese extends Human {
        public Japanese(String name) {
            super(name);
        }
    }

}
